package com.shop.item.service;

import com.shop.item.mapper.CategoryMapper;
import com.shop.item.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author : Created by HGL on 2019/03/16 13:02
 * @version : 1.0
 * Description :
 */
@Service
public class CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    public List<Category> queryByParentId(Long pid) {
        //查询条件，mapper会把对象中的非空属性作为查询条件
        Category category = new Category();
        category.setParentId(pid);
        List<Category> list = this.categoryMapper.select(category);
        //判断结果
        if(CollectionUtils.isEmpty(list)){
            return null;
        }
        return list;
    }
    public List<Category> queryByIds(List<Long> ids){
        List<Category> list = categoryMapper.selectByIdList(ids);
        //判断结果
        if(CollectionUtils.isEmpty(list)){
            return null;
        }
        return list;
    }
}
